<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('原料仓库库存列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <form id="formId">
            <input type="hidden" id="warehouseId" name="warehouseId" th:value="${warehouse.id}">
        </form>

        <div class="btn-group-sm" id="toolbar" role="group">
            <label>茶店地址：</label>
            <div class="input-group">
                <input style="display:none;" id="teaShopId" readonly="true" th:value="${teaShop.id}">
                <input style="display:none;" id="materialAmounts" readonly="true" th:value="${materialAmounts}">
                <input class="form-control" type="text" id="teaShopAddress" readonly="true" th:value="${teaShop.address}">
                <span class="input-group-addon"><i class="fa fa-search"></i></span>
            </div>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var prefix = ctx + "system/warehouse";

    $(function() {
        var options = {
            url: prefix + "/warehouseInventory/warehouseInventoryList",
            modalName: "原料仓库库存",
            columns: [{
                checkbox: true
            },
            {
                field: 'rawMaterialId',
                title: '原料编号'
            },
            {
                field: 'name',
                title: '名称'
            },
            {
                field: 'description',
                title: '描述'
            },
            {
                field: 'amount',
                title: '剩余数量(箱)'
            },
            {
                field: 'amount2',
                title: '发货数量(箱)',
                align: 'center',
                formatter: function(value, row, index) {
                    var actions = [];
                    actions.push('<input type="text" id="deliverAmount' + index + '"/>');
                    return actions.join('');
                }
            }

            ]
            };
            $.table.init(options);
        });

		function submitHandler() {
			var materialIds = $.table.selectFirstColumns();

			if (materialIds.length == 0) {
       			$.modal.alertWarning("请至少选择一条记录");
       			return;
       		}
       		var deliverAmount = new Array();
		    for (var i = 0; i < $("#materialAmounts").val(); i++) {
			    var ans = document.getElementById("deliverAmount" + i).value;
			    deliverAmount.push(ans);
		    }

			var data = {"warehouseId": $("#warehouseId").val(), "teaShopId": $("#teaShopId").val(), "materialIds": materialIds.join(), "data": deliverAmount.join()};
			$.operate.save(prefix + "/warehouseInventory/deliverMaterial/selectDeliverMaterial", data);
		}
</script>
</body>
</html>